<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 校园活动报名平台</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.3/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
    <link href="css/styles.css" rel="stylesheet">
    <link href="css/custom-icons.css" rel="stylesheet">
    <style>
        /* 登录页特定样式 */
        body {
            background: linear-gradient(135deg, #f8f9fc 0%, #e8eaf6 100%);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }
        
        .login-container {
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: center;
            padding: 2rem 0;
        }
        
        .login-card {
            background: rgba(255, 255, 255, 0.9);
            border-radius: 1rem;
            box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.1);
        }
        
        .login-form-container {
            padding: 3rem;
        }
        
        .login-header {
            text-align: center;
            margin-bottom: 2rem;
        }
        
        .login-header h1 {
            color: var(--primary-color);
            font-weight: 800;
            font-size: 2rem;
            margin-bottom: 0.5rem;
        }
        
        .login-form .form-group {
            margin-bottom: 1.5rem;
        }
        
        .login-form .form-control {
            padding: 0.75rem 1.25rem;
            font-size: 1rem;
            border-radius: 0.5rem;
        }
        
        .login-form .input-group-text {
            background-color: transparent;
            border-right: none;
            padding-right: 0;
        }
        
        .login-form .form-control:not(:first-child) {
            border-left: none;
            padding-left: 0;
        }
        
        .login-form .btn {
            padding: 0.75rem 1.25rem;
            font-size: 1rem;
            border-radius: 0.5rem;
            width: 100%;
        }
        
        .login-footer {
            text-align: center;
            margin-top: 1.5rem;
        }
        
        .back-to-home {
            margin-top: 1rem;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container login-container">
        <div class="row justify-content-center">
            <div class="col-md-8 col-lg-6 fade-in">
                <div class="login-card">
                    <div class="login-form-container">
                        <div class="login-header">
                            <h1>欢迎回来</h1>
                            <p class="text-muted">请登录您的账号</p>
                        </div>
                        
                        <form id="loginForm" class="login-form">
                            <div class="form-group">
                                <label for="loginUsername" class="form-label">用户名</label>
                                <div class="input-group">
                                    <span class="input-group-text"><i class="fas fa-user"></i></span>
                                    <input type="text" class="form-control" id="loginUsername" placeholder="请输入用户名" required>
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <label for="loginPassword" class="form-label">密码</label>
                                <div class="input-group">
                                    <span class="input-group-text"><i class="fas fa-lock"></i></span>
                                    <input type="password" class="form-control" id="loginPassword" placeholder="请输入密码" required>
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <button type="submit" class="btn btn-primary">
                                    <i class="fas fa-sign-in-alt me-2"></i>登录
                                </button>
                            </div>
                        </form>
                        
                        <div class="login-footer">
                            <p>还没有账号？<a href="register.html" class="text-primary fw-bold">立即注册</a></p>
                        </div>
                        
                        <div class="back-to-home">
                            <a href="index.html" class="text-muted">
                                <i class="fas fa-arrow-left me-1"></i>返回首页
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <footer class="footer text-center py-4">
            <p class="mb-0">© 2025 校园活动报名平台 | <i class="fas fa-code"></i> 用心打造</p>
        </footer>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.3/js/bootstrap.bundle.min.js"></script>
    <script>
        // 全局变量
        const API_BASE_URL = '/api';

        // 页面加载完成后执行
        $(document).ready(function() {
            // 登录表单提交事件
            $('#loginForm').on('submit', function(e) {
                e.preventDefault();
                login();
            });
        });

        // 登录
        function login() {
            const loginRequest = {
                username: $('#loginUsername').val(),
                password: $('#loginPassword').val()
            };

            // 显示加载状态
            const loginBtn = $('#loginForm button[type="submit"]');
            const originalText = loginBtn.html();
            loginBtn.html('<i class="fas fa-spinner fa-spin me-2"></i>登录中...');
            loginBtn.prop('disabled', true);

            $.ajax({
                url: API_BASE_URL + '/users/login',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(loginRequest),
                success: function(response) {
                    if (response.code === 200) {
                        // 登录成功，保存用户信息并跳转
                        localStorage.setItem('currentUser', JSON.stringify(response.data));
                        if (response.data.isAdmin) {
                            window.location.href = 'admin.html';
                        } else {
                            window.location.href = 'activities.html';
                        }
                    } else {
                        alert('登录失败：' + response.message);
                        // 恢复按钮状态
                        loginBtn.html(originalText);
                        loginBtn.prop('disabled', false);
                    }
                },
                error: function(xhr) {
                    alert('登录失败：' + (xhr.responseJSON?.message || '服务器错误'));
                    // 恢复按钮状态
                    loginBtn.html(originalText);
                    loginBtn.prop('disabled', false);
                }
            });
        }
    </script>
</body>
</html> 